    <div class="container-fluid" id="LG">
    <div class="row-fluid">
        <div class="span12">
            <% $.et.load('template/menu.et.html', data) %>
			<div style="margin-top: 10px;">
			</div>
            <div style="margin-top: 10px;" class="panel panel-default">
			<div class="panel-heading">
				<h2 class="panel-title">计划任务
					<button onclick="R.addTask();" style="height: 50px;width: 50px;position: fixed; top: 45px; font-size: 27px; font-weight: 900;right: 30px;border-radius: 50px;" class="btn btn-success">+</button>
				</h2>
			</div>
			<div class="panel-body">
				<table class="table">
					<thead>
						<th style="width: 80px;">任务类型</th>
						<th style="width: auto;">任务内容</th>
						<th style="width: 120px;">执行间隔</th>
						<th style="width: 50px;">操作</th>
					</thead>
					<tbody id="taskList">
					</tbody>
				</table>
			</div>
			<div class="panel-footer"><% $.et.load('template/version.et.html', data) %></div>
			</div>
        </div>
    </div>
	</div>
	<!-- 模态窗口 -->
	<!-- 模态框（Modal） -->
	<div class="modal fade" id="msg_prompt" tabindex="-1" role="dialog" 
	   aria-labelledby="myModalLabel" aria-hidden="true">
	   <div class="modal-dialog">
	      <div class="modal-content">
	         <div class="modal-header">
	            <button type="button" class="close" 
	               data-dismiss="modal" aria-hidden="true">
	                  &times;
	            </button>
	            <h4 class="modal-title">
	               	提示
	            </h4>
	         </div>
	         <div class="modal-body" >
				 <div id="prompt_alert" style="display:none;" class="alert alert-danger alert-dismissable">
				</div>
				 您确定要删除选中的计划任务么？
	         </div>
	         <div class="modal-footer">
				<button onclick="R.removeTask();" type="button" class="btn btn-warning" >确定
	            </button>
	            <button type="button" class="btn btn-default" 
	               data-dismiss="modal">取消
	            </button>
	         </div>
	      </div>
	     </div>
	</div>
	<div class="modal fade" id="addtask_modal" tabindex="-1" role="dialog" 
	   aria-labelledby="myModalLabel" aria-hidden="true">
	   <div class="modal-dialog">
	      <div class="modal-content">
	         <div class="modal-header">
	            <button type="button" class="close" 
	               data-dismiss="modal" aria-hidden="true">
	                  &times;
	            </button>
	            <h4 class="modal-title" id="myModalLabel">
	               	增加任务
	            </h4>
	         </div>
	         <div class="modal-body" id="msg_text">
				 <div id="add_alert" style="display:none;" class="alert alert-danger alert-dismissable">
				</div>
				 <form id="addForm">
					 <div style="margin-bottom: 5px;" class="input-group">
						<span class="input-group-addon">任务类型</span>
						<select onclick="R.changeDisabled(this.value);" name="type" class="form-control">
							<option value="1">系统任务</option>
							<option value="2">指令任务</option>
							<option value="3">执行程序</option>
						</select>
					</div>
					<div style="margin-bottom: 5px;" class="input-group">
						<span class="input-group-addon">任务内容</span>
						<select id="sys_content" name="content" class="form-control">
							<option value="1">开启服务器</option>
							<option value="2">关闭服务器</option>
							<option value="3">重启服务器</option>
							<option value="4">备份地图</option>
						</select>
					</div>
					<div style="margin-bottom: 5px;" class="input-group">
						<span class="input-group-addon">指令内容</span>
						<input id="cmd_content" type="text" class="form-control" disabled />
					</div>
					 <div style="margin-bottom: 5px;" class="input-group">
						<span class="input-group-addon">周期类型</span>
						<select name="exectype" class="form-control">
							<option value="1">周期任务</option>
							<option value="2">一次性任务</option>
						</select>
					</div>
					<div class="input-group">
						<span class="input-group-addon">执行周期</span>
						<input id="time" name="time" type="text" class="form-control" />
						<span class="input-group-addon"><a href='https://www.baidu.com/s?wd=cron%E8%A1%A8%E8%BE%BE%E5%BC%8F' target='_blank'>Cron表达式</a></span>
					</div>
				 </form>
	         </div>
	         <div class="modal-footer">
				 <button onclick="R.saveTask();" type="button" class="btn btn-primary">
					 保存
	             </button>
	             <button type="button" class="btn btn-default" 
	                 data-dismiss="modal">关闭
	             </button>
	         </div>
	      </div>
	     </div>
	</div>
    <script>
	R.getTasks = function(){
		webmcs.task.gettasks(function(data){
			if (!data.status){
				R.notLogin();
			}else{
				var html = "";
				for(var i=0;i<data.list.length;i++){
					html += "<tr>";
					html += "<td>"+R.getTypeName(data.list[i][1])+"</td>";
					html += "<td>"+R.getContentName(data.list[i][1],data.list[i][2])+"</td>"
					html += "<td>"+data.list[i][3]+"</td>";
					html += "<td><a href='javascript:;' onclick='R.delTask(\""+data.list[i][0]+"\");'>删除</td>";
				}
				$("#taskList").html(html);
			}
		});
	}
	R.getContentName = function(type, content){
		if(type == "2" || type == "3")
			return content;
		switch(content){
			case "1":
				return "开启服务端";
			case "2":
				return "关闭服务端";
			case "3":
				return "重启服务端";
			case "4":
				return "备份地图";
			default:
				return "ERROR";
		}
	}
	R.getTypeName = function(type){
		if (type == "1")
			return "系统任务";
		else if (type == "2")
			return "指令任务";
		else 
		  return "执行程序";
	}
	R.changeDisabled = function(text){
		if(text == "2" || text == "3"){
			$("#sys_content").attr("name","");
			$("#sys_content").prop("disabled",true);
			$("#cmd_content").attr("name","content");
			$("#cmd_content").prop("disabled",false);
		}else{
			$("#cmd_content").attr("name","");
			$("#cmd_content").prop("disabled",true);
			$("#sys_content").attr("name","content");
			$("#sys_content").prop("disabled",false);
		}
	}
	R.addTask = function(){
		$("#addForm")[0].reset();
		R.changeDisabled(1);
		$("#addtask_modal").modal("show");
	}
	R.delTask = function(id){
		R.taskId = id;
		$("#msg_prompt").modal("show");
	}
	R.removeTask = function(){
		webmcs.task.deltask(R.taskId, function(data){
			if (data.status){
				R.getTasks();
				$("#msg_prompt").modal("hide");
			}else{
				switch(data.msg){
					case "NOTLOGIN":
						$("#msg_prompt").modal("hide");
						R.notLogin();
						break;
					case "IDERROR":
						R.showAlert("ID不存在，请刷新重试！","prompt_alert");
						break;
					case "NETERROR":
						R.showAlert("网络异常，服务器连接失败！", "prompt_alert")
						break;
				}
			}
		});
	}
	R.saveTask = function(){
		webmcs.task.addtask($('#addForm').serialize(), function(data){
			if (data.status){
				R.getTasks();
				$("#addtask_modal").modal("hide");
			}else{
				switch(data.msg){
					case "NOTLOGIN":
						$("#addtask_modal").modal("hide");
						R.notLogin();
						break;
					case "PARAMERROR":
						R.showAlert("参数错误，请检查Cron表达式是否正确！推荐使用<a href='https://www.baidu.com/s?wd=cron%E8%A1%A8%E8%BE%BE%E5%BC%8F%E7%94%9F%E6%88%90%E5%99%A8' target='_blank'>Cron表达式在线生成器</a>","add_alert");
						break;
					case "NETERROR":
						R.showAlert("网络异常，服务器连接失败！","add_alert");
						break;
				}
			}
		});
	}
	R.taskId = null;
	R.getTasks();
    </script>